using Cjj.Exam.Hangfire;

namespace Cjj.Hangfire
{
    public class Program
    {
        //public static void Main(string[] args)
        //{
        //    var builder = WebApplication.CreateBuilder(args);

        //    // Add services to the container.
        //    builder.Services.AddRazorPages();

        //    var app = builder.Build();

        //    // Configure the HTTP request pipeline.
        //    if (!app.Environment.IsDevelopment())
        //    {
        //        app.UseExceptionHandler("/Error");
        //        // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
        //        app.UseHsts();
        //    }

        //    app.UseHttpsRedirection();
        //    app.UseStaticFiles();

        //    app.UseRouting();

        //    app.UseAuthorization();

        //    app.MapRazorPages();

        //    app.Run();
        //}


        public async static Task<int> Main(string[] args)
        {
            //            Log.Logger = new LoggerConfiguration()
            //#if DEBUG
            //                .MinimumLevel.Debug()
            //#else
            //            .MinimumLevel.Information()
            //#endif
            //                .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
            //                .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
            //                .Enrich.FromLogContext()
            //                .WriteTo.Async(c => c.File("Logs/logs.txt"))
            //                .WriteTo.Async(c => c.Console())
            //                .CreateLogger();

            try
            {
                // Log.Information("Starting Cjj.Exam.HttpApi.Host.");
                var builder = WebApplication.CreateBuilder(args);
                builder.Host.AddAppSettingsSecretsJson();
                //.UseAutofac()
                //.UseSerilog();
                await builder.AddApplicationAsync<ExamHangfireModule>();
                var app = builder.Build();
                await app.InitializeApplicationAsync();
                await app.RunAsync();
                return 0;
            }
            catch (Exception ex)
            {
                if (ex is HostAbortedException)
                {
                    throw;
                }

                // Log.Fatal(ex, "Host terminated unexpectedly!");
                return 1;
            }
            finally
            {
                //Log.CloseAndFlush();
            }
        }
    }
}